
__author__ = 'FJF'
# -*- coding:utf-8 -*-
import xlrd
import xlwt
from xlutils.copy import copy
import os

filenames = []
def getname( ):
    filedir = 'F:\\test\\'
    filename = os.listdir( filedir )
    return filename

filenames = getname( )

def dealwithExcel( filename ):
    filepath = 'F:\\test\\' + filename
    old_excel = xlrd.open_workbook( filepath, formatting_info = True )
    new_excel = copy( old_excel )
    old_ws = old_excel.sheets( )[0]
    #修改单元格值
    Cell_D26 = old_ws.cell_value( 25, 3 )
    Cell_D26 = Cell_D26.replace( "土地面积：", '' )
    Cell_D26 = Cell_D26.replace( "；\n", '/' )
    Cell_D26 = Cell_D26.replace( "房屋面积：", '' )
    Cell_H26 = old_ws.cell_value( 25, 7 )
    Cell_H26 = Cell_H26.replace( "/", '' )
    #写入单元格新值
    new_ws = new_excel.get_sheet( 0 )
    new_ws.write( 25, 3, Cell_D26 )
    new_ws.write( 25, 7, Cell_H26 )
    #保存
    new_excel.save( filepath )
count =0
for i in filenames:
    dealwithExcel(i)
    count=count+1
    print("已修改："+i+"               "+ str(count/len(filenames)*100)+"%")